package com.xhkj.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.image.*;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping
public class ChatController {

    private final ChatClient chatClient;
    private final ChatModel chatModel;
    private final ImageModel imageModel;

    public ChatController(ChatClient.Builder builder, ChatModel chatModel, ImageModel imageModel) {
        this.chatClient = builder.build();
        this.chatModel = chatModel;
        this.imageModel = imageModel;
    }

    @GetMapping("/chat1")
    public String chat(String input) {
        return this.chatClient.prompt()
                .user(input)
                .call()
                .content();
    }

    @PostMapping("/chat2")
    public String chatS(String input) {
        ChatResponse response = chatModel.call(new Prompt(input));
        return response.getResult().getOutput().getContent();
    }





    @RequestMapping("/image")
    public String image(String input) {
        ImageOptions options = ImageOptionsBuilder.builder()
                .withModel("dall-e-3")
                .build();

        ImagePrompt imagePrompt = new ImagePrompt(input, options);
        ImageResponse response = imageModel.call(imagePrompt);
        String imageUrl = response.getResult().getOutput().getUrl();

        return "redirect:" + imageUrl;
    }






}